#include "openglrendercontrol.h"
#include "openglrenderer.h"

using namespace PBVP;

OpenGLRenderControl::OpenGLRenderControl(OpenGLRenderer *pGLRenderer, QWidget *parent)
: QWidget(parent)
{
	m_pRender = pGLRenderer;
	ui.setupUi(this);

	if (m_pRender->isWireFrame())
	{
		ui.wireframeCheckBox->setCheckState(Qt::Checked);
	}
	switch (m_pRender->shadingMode())
	{
	case GL_SMOOTH:
		ui.smoothRadioButton->setChecked(true);
		break;
	case GL_FLAT:
		ui.flatRdioButton->setChecked(true);
		break;
	}
	ui.colorLabel->setColor(m_pRender->m_Color);

	connect(ui.wireframeCheckBox, SIGNAL(stateChanged(int)), this, SLOT(setWireFrame(int)));
	connect(ui.smoothRadioButton, SIGNAL(toggled(bool)), this, SLOT(setShadingMode()));
	connect(ui.colorLabel, SIGNAL(colorChanged(const QColor&)), m_pRender, SLOT(setColor(const QColor&)));
	connect(ui.transparencySlider, SIGNAL(valueChanged(int)), m_pRender, SLOT(setTransparency(int)));
	connect(ui.showCheckBox, SIGNAL(stateChanged(int)), m_pRender, SLOT(setVisible(int)));
	connect(ui.bboxCheckBox, SIGNAL(stateChanged(int)), m_pRender, SLOT(showBBox(int)));
}

//////////////////////////////////////////////////////////////////////////
// Public slots
//////////////////////////////////////////////////////////////////////////
void OpenGLRenderControl::setWireFrame(int state)
{
	switch(state) {
	case Qt::Checked:
		m_pRender->setWireFrame(true);
		break;
	case Qt::Unchecked:
		m_pRender->setWireFrame(false);
		break;
	}
}

void OpenGLRenderControl::setShadingMode()
{
	if(ui.smoothRadioButton->isChecked()) {
		m_pRender->setShadingMode(GL_SMOOTH);
	} else {
		m_pRender->setShadingMode(GL_FLAT);
	}
}

